src/capitalize.js
thoward37@gmail.com/shirt[create-new-file-src-capitalize-js] / src / capitalize.js
@ aae2fdad
Download
/**
* Capitalizes the first character of a string.
*
* @param {string} s - The string to capitalize.
* @returns {string} - The capitalized string.
* @throws {TypeError} - If the input is not a string.
*/
export function capitalize(s) {
if (typeof s !== 'string') {
throw new TypeError('Input must be a string');
}
if (s.length === 0) {
return s;
}
return s[0].toUpperCase() + s.slice(1);
}